package gdconf

import (
	"server_cluster/common/logger"
)

// 钓鱼点配置表

type FishPointConfig struct {
	FishPointId int32        `csv:"ID" gorm:"primary_key;autoIncrement:false"` // 钓鱼点id
	FishPool    IdWeightList `csv:"Func,omitempty"`                            // 随机鱼池
}

func (f *FishPointConfig) TableName() string {
	return "config_fish_point"
}

func (g *GameDataConfig) saveFishPointConfig() {
	saveTableToDb[FishPointConfig](g.Db, readTable[FishPointConfig](g.CsvPathPrefix+"FishingSpots.csv"))
}

func (g *GameDataConfig) loadFishPointConfig() {
	g.GameDataMaps.FishPointConfigMap = make(map[int32]*FishPointConfig)
	for _, fishPointConfig := range loadTableFromDb[FishPointConfig](g.Db) {
		g.GameDataMaps.FishPointConfigMap[fishPointConfig.FishPointId] = fishPointConfig
	}
	logger.Info("FishPointConfig Count: %v", len(g.GameDataMaps.FishPointConfigMap))
}

func GetFishPointConfig(fishPointId int32) *FishPointConfig {
	value, exist := CONF.GameDataMaps.FishPointConfigMap[fishPointId]
	if !exist {
		logger.Error("[ConfigNotFound] FishPointConfig, fishPointId: %v", fishPointId)
		return nil
	}
	return value
}

func GetFishPointConfigMap() map[int32]*FishPointConfig {
	return CONF.GameDataMaps.FishPointConfigMap
}
